package org.traffometer.packet.location;

/**
 * Implements a representation for a latitude coordinate. 
 *
 * @author Aaron A. Kagawa
 * @version $Id$
 */
public class Latitude extends PhysicalCoordinate {
  
  /**
   * Constructs a Latitude with the specified degrees, minutes, seconds, and direction.
   * @param degrees The Latitude degrees. This value must be positive.
   * @param minutes The Latitude minutes. This value must be positive.
   * @param seconds The Latitude seconds. This value must be positive.
   * @param hemisphere The Latitude's hemisphere either Hemisphere.North or Hemisphere.South.
   * @throws LocationException If an invalid parameters is passed to this constructor. 
   */
  public Latitude(int degrees, int minutes, double seconds, Hemisphere hemisphere)
    throws LocationException {
    super(degrees, minutes, seconds, hemisphere);
    if (hemisphere != Hemisphere.North && hemisphere != Hemisphere.South) {
      throw new LocationException("Invalid hemisphere. Must be either North or South");
    }
  }
  
  /**
   * Constructs a Latitude based on its sexagesimal notation.
   * @param coordinateInSexagesimal The physical coordinate in sexagesimal units.
   */
  public Latitude(double coordinateInSexagesimal) {
    super(coordinateInSexagesimal);
  }
    
  /**
   * Constructs a copy of the specified Latitude object.
   * @param latitude The Latitude object to be copied. 
   */
  public Latitude(Latitude latitude) {
    this(latitude.toSexagesimal());
  }
  
  /**
   * Returns the hemisphere that this Latitude object is associated with. 
   * @return the hemisphere, either Hemisphere.EAST or Hemisphere.WEST.
   */
  public Hemisphere getHemisphere() {
    if (super.coordinateInSexagesimal > 0) {
      return Hemisphere.North;
    }
    else {
      return Hemisphere.South;
    }
  }
  
  /**
   *  Returns a string representation of this Latitude object.
   *  @return A string representation of this Latitude object.
   */
  public String toString() {
    if (this.getHemisphere() == Hemisphere.South) {
      return getDegrees() + " " + this.getMinutes() + "'" + this.getSeconds() + "'' S";
    }
    else {
      return getDegrees() + " " + this.getMinutes() + "'" + this.getSeconds() + "'' N";
    }
  }
  
}